<template>
  <div class="app-container">
    <el-row style="margin-top: 3px; margin-bottom: 10px;">
      <el-col :span="12" style="text-align: right">
        <div style="padding: 0 20px 0 0">
          <el-button type="primary" @click="onImport">导入</el-button>
        </div>
      </el-col>
      <el-col :span="12" style="text-align: right">
        <div style="padding: 0 20px 0 0">
          <el-button type="success" @click="all">批量下载</el-button>
        </div>
      </el-col>
    </el-row>
    <el-table
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
    >
      <el-table-column label="序号" width="70" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.numberNo }}</span>
        </template>
      </el-table-column>
      <el-table-column label="企业名称" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.entName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="发展评分" width="100" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.targetScore }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创新型评分" width="120" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.innovateScore }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创新型评测" width="120" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.innovationContent }}</span>
        </template>
      </el-table-column>
      <el-table-column label="专精特新评分" width="120" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.refinementScore }}</span>
        </template>
      </el-table-column>
      <el-table-column label="专精特新评测" width="120" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.refinementContent }}</span>
        </template>
      </el-table-column>
      <el-table-column label="小巨人评测" width="120" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.giantContent }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" prop="created_at" label="操作" width="160">
        <template slot-scope="scope">
          <el-button-group>
            <el-button type="primary" size="mini" @click="toReport(scope.$index)">查看详情</el-button>
          </el-button-group>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import Excel from '@/utils/excel2'

export default {
  name: 'ImportList2',
  filters: {
    statusFilter(status) {
      const statusMap = {
        0: 'warning',
        1: 'success',
        9: 'danger'
      }
      return statusMap[status]
    },
    statusFormat(status, msg) {
      const statusMap = {
        1: '已保存',
        0: '未保存',
        9: msg
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      updateDialog: false,
      list: [],
      info: {
        numberNo: '',
        entName: '',
        targetScore: '',
        innovateScore: '',
        innovationContent: '',
        refinementScore: '',
        refinementContent: '',
        giantContent: ''
      },
      index: 0,
      listLoading: true
    }
  },
  created() {

  },
  methods: {
    onImport() {
      Excel.importExcel((data, dataRef) => {
        const temp = data
        if (temp === null) {
          return
        }
        if (temp.length === 0) {
          return
        }
        this.list = temp
      })
    },
    toReport(index) {
      // const routes = this.$router.resolve({ name: 'ReportPdf', query: { userId: userId, year: year, cityCode: cityCode }})
      // window.open(routes.href, '_blank')
      this.$router.push({ name: 'ReportPdf2', query: { numberNo: this.list[index].numberNo, entName: this.list[index].entName,
        targetScore: this.list[index].targetScore, innovateScore: this.list[index].innovateScore, innovationContent: this.list[index].innovationContent,
        refinementScore: this.list[index].refinementScore, refinementContent: this.list[index].refinementContent,
        giantContent: this.list[index].giantContent }})
    },
    all() {
      if (this.list.length > 0) {
        this.interval = window.setInterval(this.open, 5000)
      }
    },
    open() {
      if (this.index < this.list.length) {
        this.$router.push({ name: 'ReportPdf2', query: { numberNo: this.list[this.index].numberNo, entName: this.list[this.index].entName,
          targetScore: this.list[this.index].targetScore, innovateScore: this.list[this.index].innovateScore, innovationContent: this.list[this.index].innovationContent,
          refinementScore: this.list[this.index].refinementScore, refinementContent: this.list[this.index].refinementContent,
          giantContent: this.list[this.index].giantContent, auto: '1' }, params: { id: this.list[this.index].numberNo }})
        this.index = this.index + 1
      } else {
        this.index = 0
        clearInterval(this.interval)
      }
    }
  }
}
</script>
<style scoped>

</style>
